package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.activity.MyHomeActivityV2;
import com.runen.infinitemovement.model.entity.CompanyHomeTimesRankingEntity;
import com.runen.infinitemovement.tool.CommonUtil;
import com.runen.infinitemovement.tool.GlideUtils;
import com.runen.infinitemovement.widget.imageview.RoundedCornersImage;


public class CompanyHomeRankingAdapter extends BaseQuickAdapter<CompanyHomeTimesRankingEntity.DataBean, BaseViewHolder> implements LoadMoreModule {
    private Context context;

    public CompanyHomeRankingAdapter(Context context) {
        super(R.layout.item_company_home_ranking);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CompanyHomeTimesRankingEntity.DataBean item) {
        ImageView iv_ranking = helper.getView(R.id.iv_ranking);
        TextView tv_img_ranking_num = helper.getView(R.id.tv_img_ranking_num);
        TextView tv_ranking_num = helper.getView(R.id.tv_ranking_num);
        RoundedCornersImage rci_user_header = helper.getView(R.id.rci_user_header);
        TextView tv_user_name = helper.getView(R.id.tv_user_name);
        TextView tv_minute = helper.getView(R.id.tv_minute);
        TextView tv_sports_num = helper.getView(R.id.tv_sports_num);
        TextView tv_enter_num = helper.getView(R.id.tv_enter_num);
        LinearLayout ll_bg = helper.getView(R.id.ll_bg);
        int point = helper.getAdapterPosition();
        if (point % 2 == 0) {
            ll_bg.setBackgroundColor(CommonUtil.getColor(R.color.color_FFF9F8F9));
        } else {
            ll_bg.setBackgroundColor(CommonUtil.getColor(R.color.white));
        }
        switch (point) {
            case 0:
                GlideUtils.loadImage(context, CommonUtil.getDrawable(R.mipmap.ico_ranking1), iv_ranking);
                tv_img_ranking_num.setText(String.valueOf((point + 1)));
                iv_ranking.setVisibility(View.VISIBLE);
                tv_img_ranking_num.setVisibility(View.VISIBLE);
                tv_ranking_num.setVisibility(View.GONE);
                break;
            case 1:
                GlideUtils.loadImage(context, CommonUtil.getDrawable(R.mipmap.ico_ranking2), iv_ranking);
                tv_img_ranking_num.setText(String.valueOf((point + 1)));
                iv_ranking.setVisibility(View.VISIBLE);
                tv_img_ranking_num.setVisibility(View.VISIBLE);
                tv_ranking_num.setVisibility(View.GONE);
                break;
            case 2:
                GlideUtils.loadImage(context, CommonUtil.getDrawable(R.mipmap.ico_ranking3), iv_ranking);
                tv_img_ranking_num.setText(String.valueOf((point + 1)));
                iv_ranking.setVisibility(View.VISIBLE);
                tv_img_ranking_num.setVisibility(View.VISIBLE);
                tv_ranking_num.setVisibility(View.GONE);
                break;
            default:
                tv_ranking_num.setText(String.valueOf((point + 1)));
                iv_ranking.setVisibility(View.GONE);
                tv_img_ranking_num.setVisibility(View.GONE);
                tv_ranking_num.setVisibility(View.VISIBLE);
                break;
        }
        GlideUtils.loadImage(context, item.headImgUrl + "?x-oss-process=image/resize,m_fill,w_144,h_144", rci_user_header);
        tv_user_name.setText(item.nickname);
        tv_minute.setText(item.sportTimeLength + "分钟");
        tv_sports_num.setText(item.sportTimes);
        tv_enter_num.setText(item.activityTimes);

        rci_user_header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MyHomeActivityV2.class);
                intent.putExtra("userId", item.id);
                context.startActivity(intent);
            }
        });

    }
}
